﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Lm.Common.DAL.ModelCodeGenerator
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnGenerate_Click(object sender, EventArgs e)
        {
            try
            {
                var dtTableInfo = new SQLTableInfoReader(
                    this.txtServer.Text.Trim(),
                    this.txtDB.Text.Trim(),
                    this.txtAccount.Text.Trim(),
                    this.txtPassword.Text.Trim()
                    ).Read();
                var modelList = new ModelParser().Parse(dtTableInfo);
                new Generator().Generate(
                    this.txtDir.Text.Trim(),
                    this.txtNameSpace.Text.Trim(),
                    modelList,
                    this.txtExcludedTable.Text.Split(new string[]{"\r\n"}, StringSplitOptions.RemoveEmptyEntries).ToList()
                );
                MessageBox.Show("完成");
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message);
            }
        }

        private void btnSelectDir_Click(object sender, EventArgs e)
        {
            if (this.folderBrowserDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                this.txtDir.Text = this.folderBrowserDialog1.SelectedPath;
            }
        }

        private void label6_Click(object sender, EventArgs e)
        {

        }
    }
}
